<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
     <title>物业账号</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <link rel="stylesheet" href="../css/admin.css">
    <link rel="stylesheet" href="../css/account.css">
    <link rel="stylesheet" href="../fonts/iconfont.css">
</head>
<style>
.container{
     display: flex;
     background-color:#F3F3F3;
}
.bg-gray{
     background-color: #dfdfdf;
}
.detail{
     height:600px;
}
.layui-table[lay-skin=line] td, .layui-table[lay-skin=line] th{
     background-color:#fff;
}
.layui-table td, .layui-table th{
    padding:14px 15px;
  }
form{
    float:left;
    margin-top:10px;
    display: inline-block;
  }
.layui-layer-btn,.layui-layer-content{
    text-align:center;
  }
</style>
<body>
  <div class="container">
      <!-- 列表-->
      <div class="section-right">
      <div class="right-top">
         <!-- 搜索栏 -->
      <div class="org-search"  name="myform">
      <input type="text" name="name" id="wuye_name" value=""  placeholder="按物业公司搜索" onfocus="this.style.color='#888';"  onblur="this.style.color='#2C283C'; "/>
          <div id="search" style="cursor: pointer; "><i class="layui-icon" style="font-size: 25px; color: #EF7632;">&#xe615;</i> </div>
        </div>
         <!-- 搜索栏 -->
       <button class="layui-btn layui-btn-normal  left-1 "><span class="pic-3 iconfont icon-tianjiarenyuan"></span>添加账号</button>

        <button class="layui-btn layui-btn-danger  a4 right"><span class="pic-4 iconfont icon-shanchu"></span>删除</button>
        <button class="layui-btn layui-btn-normal  add right"><span class="pic-4 iconfont icon-modify"></span>修改</button>
           </div>

<!--  table部分 -->
<div class="detail">
      <table class="layui-table" lay-skin="line"  id="table">
      <thead>
         <tr>
           <th></th>
           <th>物业公司</th>
           <th>用户名称</th>
           <th>账&emsp;号</th>
           <th>账号角色</th>
           <th>分管小区</th>
         </tr>
      </thead>
      <tbody class="org-table">
      </tbody>
      </table>
    <div id="page-fen">
        <div id="page-num"></div>
    </div>
    </div>
  </div>
    </div>
  <script src="../lib/jquery.js" type="text/javascript"></script>
  <script type="text/javascript" src="../layui/layui.js"></script>
  <script type="text/javascript" src="../js/account.js"></script>
  <script src="../lib/js/jquery.cookie.js" type="text/javascript"></script>
  <script>
      layui.use(['jquery','form','laypage','element','layer'], function(){
        var $ = layui.jquery;
        var layer = layui.layer;
        var laypage = layui.laypage;

        var form = layui.form();

        var name=$("#name").val();
        var name="";

        $("#search").off("click").on("click",function(){
           name = $.trim($("#wuye_name").val());
           searchTable();
        })
//回车搜索
        $("#wuye_name").on('keydown', function(e){
            if(e.keyCode == 13){
            name = $.trim($("#wuye_name").val());
            searchTable();
                }
            });
            //点击查看
        seeData();
        function seeData(set_Up){
          $(document).off("click", ".see").on("click", ".see", function() {
            if(set_Up){
                layer.open({
                  type:2
                  ,shade:[0.1, '#fff']
                  ,area:['350px', '300px']
               ,title:['小区分管详情','font-weight:600;text-align:center;font-size:16px;border-radius:10px;']
                  ,content: 'add-management.html'
              })
              }else{
              alert("请先选定用户角色");
            }
            })
        };
      //xiugai 弹窗
         xiugai();
         function xiugai(currentData){
          $(document).off("click", ".add").on("click", ".add", function() {
              if(currentData){
                  layer.open({
                  type:2
                  ,shade:[0.1, '#fff']
                  ,area:['350px', '370px']
                  ,title:['修改信息','font-weight:600;text-align:center;font-size:16px;border-radius:10px;']
                  ,content: 'fix-account.html',
                success: function(layero, index){
                    var body = layer.getChildFrame('body', index);
                        body.contents().find("#company_name").val(currentData.company_name);
                        body.contents().find("#user_name").val(currentData.user_name);
                        body.contents().find("#user_tel").val(currentData.user_tel);
                }
              })
            }else{
              alert("请先选中一条数据");
            }
          })
      };
//删除
   delData();
   function delData(currentData){
         $(document).off("click",".a4").on("click", ".a4", function() {
              if(currentData){
                layer.open({
                 /*type:1,*/
                 shade:[0.1, '#fff']
                ,title:['删除操作','font-weight:600;text-align:center;font-size:16px;border-radius:10px;']
                ,content: '您确认要删除吗？'
                ,btn: ['取消', '确认']
                ,yes: function(index, layero){
                   layer.closeAll();
                }
               ,btn2: function(index, layero){
               var user_id = currentData.user_id
                   console.log(user_id);
                    $.ajax({
                        url: '../../wuye_account/delWuYeUser',
                        type: 'post',
                        dataType: 'json',
                        data:{
                          user_id:user_id
                        }
                    })
                   .done(function() {
                     layer.msg('删除成功！',{time: 1000});
                     window.location.reload();
                    })
                    .fail(function() {
                        console.log("error");
                    });
                     layer.closeAll();
                    }
            })
           }else{
              alert("请先选中一条数据del");
            }
          });
      };

//获取信息

      var pages = {};
      searchTable();
        function searchTable(current_page){
        var tableData;
          $.ajax({
              url: '../../wuye_account/queryWuYeUser',
              type: 'get',
              dataType: 'json',
              data:{
                  name :name,
                  current_page: current_page||1,
                  limit:10
              }
           })
         .done(function(response){
             console.log(response);

          if(response.resultCode == 200){
             console.log("success");

          var str= '';
          console.log(response.page.list.length);
          if(response.page.list.length){
             tableData = response.page.list;
             console.log(tableData);

            for(var i=0;i<response.page.list.length;i++){
            str +=
            '<tr>'+
            '<td class="check"><input type="radio" name="items" title="" lay-skin="primary" data-id="'+ response.page.list[i].user_id +'"></td>'+
            '<td>'+ response.page.list[i].company_name +'</td>'+
            '<td>'+ response.page.list[i].user_name +'</td>'+
            '<td>'+ response.page.list[i].user_tel+'</td>'+
            '<td>'+ response.page.list[i].role_name+'</td>'+
            '<td><button data-id="'+ response.page.list[i].user_id +'"  class="see">设&nbsp;置&nbsp;></button></td>'+
            '</tr>'
          }
          $(".org-table").html(str);

            form.render();

              $("td .see").click(function(){
                  var set_Up= $(this).data("id");
                 localStorage.setItem("set_Up", set_Up);
                  console.log(set_Up);
                  seeData(set_Up);
              });

            $("#table>tbody>tr>td>input").change(function(){
            console.log(123456);
            if($(this).is(':checked')){
               console.log("选中1");
              var currentId =  $(this).attr("data-id");
                for(var i=0;i<tableData.length;i++){
                  if(tableData[i].user_id == currentId){
                    var currentData = tableData[i];
                        console.log(currentData.user_id);
                        console.log(currentData.role_name);

             localStorage.setItem("wuyeID", currentData.user_id);
             localStorage.setItem("roleNameID", currentData.role_name);
                  }
                }
            }else{
               var currentId='';
            }
/*            $("#table tbody tr td input").removeClass('bg-gray');
            $(this).addClass('bg-gray');
              console.log(currentData);
              console.log(currentId );*/

              /*seeData(currentData);*/
              delData(currentData);
              xiugai(currentData);
            });

    /*显示分页*/
            pages.total = response.page.total;
            pages.current_page = response.page.current_page;
            pages.totalPages = Math.ceil(pages.total/10);

         laypage({
            cont: 'page-num'
            ,pages: pages.totalPages
            ,curr: pages.current_page //当前页
            ,first: false
            ,last:false
            ,prev: '<em><</em>'
            ,next: '<em>></em>'
            ,jump: function(obj, first){ //触发分页后的回调
            var curr = obj.curr;
                console.log(curr);
            if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr
              searchTable(obj.curr);
                };
              }
          })//分页
        }
        else{
          str = '<tr><td colspan="7">暂无数据</td></tr>';
          $(".org-table").html(str);
         }
        }//200
        })//done
           .fail(function(response){
              console.log("fail",response);
              if(response.resultCode=='001'){
                console.log("param is not found");
                }else if(response.resultCode=='009'){
                  console.log("String is not int type");
                }
            })//fail
        } //seach
    });//模块加载
  </script>
</body>
</html>
